package ar.uba.dc.cmovil.tripplanner.widget;

import android.content.Context;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by anton on 10/17/13.
 */
public class TextAndDateWidget extends LinearLayout {

    private EditText text;
    private DatePicker datePicker;

    public TextAndDateWidget(Context context, String textLabel) {
        super(context);

        this.setOrientation(VERTICAL);

        text = new EditText(context);
        text.setHint(textLabel);
        this.addView(text);

        datePicker = new DatePicker(context);
        this.addView(datePicker);
    }

    public TextAndDateWidget(Context context, String textLabel, Date minDate) {
        this(context, textLabel);
        datePicker.setMinDate(minDate.getTime());
    }

    public String getText() {
        return text.getText().toString();
    }

    public Date getDate() {
        int year = datePicker.getYear();
        int month = datePicker.getMonth();
        int day = datePicker.getDayOfMonth();

        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);

        return calendar.getTime();
    }
}
